<template>
    <h2 style="text-align: center">用户借款列表</h2>
    借款名称 <input type="text" v-model="BI_name">
    利息 <select v-model="BT_id">
            <option value=0>--请选择--</option>
            <option v-for="item in infos" :value="item.BT_id">{{ item.BT_name }}%</option>
        </select>
    <input type="button" value="查询" @click="show()">
    <input type="button" value="正序" @click="show()">
    <input type="button" value="倒序" @click="order()">
    <table border="1">
        <tr>
            <td>借款ID</td>
            <td>借款名称</td>
            <td>借款最高金额</td>
            <td>借款年限</td>
            <td>利息</td>
            <td>借款简介</td>
            <td>借款发布时间</td>
            <td>操作</td>
        </tr>
        <tr v-for="item in info">
            <td>{{item.BI_id}}</td>
            <td>{{item.BI_name}}</td>
            <td>{{item.BI_maxmoney}}CNY</td>
            <td>{{item.BI_year}}</td>
            <td>{{item.BT_name}}%</td>
            <td>{{item.BI_result}}</td>
            <td>{{(item.BI_date).substring(0,10)}}</td>
            <td>
                <slot :id="item.BI_id"></slot>
            </td>
        </tr>
    </table>
    共有{{count}}条数据，每页显示{{pagesize}}条数据，当前{{pageindex}}/{{pagecount}}页
    <a href="#" @click="updcount(1)">首页</a>
    <a href="#" @click="updcount(pageindex-1)">上一页</a>
    <a href="#" @click="updcount(pageindex+1)">下一页</a>
    <a href="#" @click="updcount(pagecount)">尾页</a>
</template>
<script setup lang="ts">
import axios from "axios"
import { ref,onMounted } from "vue"
import { useRouter } from "vue-router"
const router = useRouter()

let count=0
let pageindex=1
let pagesize=2
let pagecount=0

const BI_name=ref("")
const BT_id=ref(0)

const infos=ref({
    BT_id:0,
    BT_name:""
})
const info=ref([{
    BI_id:"",
    BI_name:"",
    BI_maxmoney:"",
    BI_year:"",
    BI_result:"",
    BI_date:"",
    BT_id:0,
    BT_name:""
}])



const Bind=()=>{
    axios({
        url:"http://localhost:52342/api/Borrow/Bind",
        method:"get",
    })
    .then((res)=>{
        infos.value=res.data
        console.log(res.data)
    })
    .catch((err)=>{
        console.log(err)
    })
}
onMounted(()=>{
    Bind()
    show()
})

const show =()=>{
    axios({
        url:"http://localhost:52342/api/Borrow/BorrowShow",
        method:"get",
        params:{
            BI_name:BI_name.value,
            BT_id:BT_id.value,
            pageindex:pageindex,
            pagesize:pagesize
        }
    })
    .then((res)=>{
        console.log(res.data)
        count=res.data.count
        pagecount=res.data.pagecount
        info.value=res.data.list
    })
    .catch((err)=>{
        console.log(err)
    })
}

const order =()=>{
    axios({
        url:"http://localhost:52342/api/Borrow/BorrowOrderby",
        method:"get",
        params:{
            BI_name:BI_name.value,
            BT_id:BT_id.value,
            pageindex:pageindex,
            pagesize:pagesize
        }
    })
    .then((res)=>{
        console.log(res.data)
        count=res.data.count
        pagecount=res.data.pagecount
        info.value=res.data.list
    })
    .catch((err)=>{
        console.log(err)
    })
}





const updcount=(num:any)=>{
    
    if(num>=1&&num<=pagecount){
        pageindex=num
        show()
    }else{
        alert("页码有误")
        return
    }
}

const tiao=(BI_id:any)=>{
    router.push({
        path:"/BorrowUserAdd",
        query:{
            BI_id:BI_id
        }
    })
}




</script>
